﻿using System;
using System.Collections.Generic;
using System.Text;
using Motorbike.Model;
using ComponentFactory.Krypton.Toolkit;

namespace Motorbike.APP
{
    partial class ApplicationContext
    {
        #region System admin define
        public const string Admin_UserId = "HongBing.Motorbike.Admin";
        protected const string Admin_UserCode = "admin";
        protected const string Admin_UserName = "System Administrator";
        protected const string Admin_Password = "CQ123456789";

        public User LoginAdmin(string loginCode, string password)
        {
            if (Admin_UserCode.Equals(loginCode.Trim()) && Admin_Password.Equals(password.Trim()))
            {
                User admin = new User();
                admin.Id = Admin_UserId;
                admin.Code = Admin_UserCode;
                admin.Name = Admin_UserName;
                admin.Password = Admin_Password;
                admin.CreateDate = DateTime.Now;
                admin.RoleId = Role.SysAdmin;
                return admin;
            }
            return null;
        }
        #endregion

        #region Single Model
        private static ApplicationContext _instance;

        public static ApplicationContext Instance
        {
            get
            {
                if (null == _instance)
                {
                    lock (typeof(ApplicationContext))
                    {
                        if (null == _instance)
                        {
                            _instance = new ApplicationContext();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion

        private IDictionary<Role, KryptonListItem> allRoleItems;

        private ApplicationContext()
        {
            #region initialize list items of the role.
            allRoleItems = new Dictionary<Role, KryptonListItem>();
            KryptonListItem listItem = new KryptonListItem("管理员");
            listItem.Tag = Role.AppAdmin;
            allRoleItems.Add(Role.AppAdmin, listItem);
          
            listItem = new KryptonListItem("操作员");
            listItem.Tag = Role.AppOperator;
            allRoleItems.Add(Role.AppOperator, listItem);
            #endregion

        }

        public ICollection<KryptonListItem> GetAllRolItems()
        {
            return this.allRoleItems.Values;
        }

        public KryptonListItem GetRoleItem(Role role)
        {
            return this.allRoleItems[role];
        }

        #region Members
        /// <summary>
        /// 当前用户
        /// </summary>
        public User CurrentUser { get; set; }

        public LoginLog CurrentLoginLog { get; set; }

        //public LoginLog 
        #endregion
    }
}
